﻿using System.Diagnostics;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;

namespace Sharp.Infrastructure.Wcf
{
    [DebuggerStepThrough]
    public class ContextSender: IClientMessageInspector
    {
        public void AfterReceiveReply(ref Message reply, object correlationState) { }
        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            var contextHeader = new MessageHeader<ContactContext>(ContactContext.Current);
            request.Headers.Add(contextHeader.GetUntypedHeader(ContactContext.ContextHeaderLocalName,
                                                               ContactContext.ContextHeaderNamespace));
            return null;
        }
    }
}
